package com.paas.demo.controller;

import com.paas.demo.common.PJson;
import com.paas.demo.service.UploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@Api(value="视频控制接口")
@RestController
public class DownLoadController {

    @Autowired
    private UploadService uploadService;

    @ApiOperation("前端-上传")
    @PostMapping("/web/v1/insp/report")
    public PJson report(@RequestParam(name= "video_id",required = true)long video_id, MultipartFile video_file) throws Exception{

        // 保存文件到本地
        String localUrl = uploadService.tranferFile(video_file, "INSP", "C:\\workspace\\data");


        return PJson.succ().data(localUrl);
    }

    @ApiOperation("前端-下载")
    @GetMapping("/web/v1/insp/down")
    public void firmDown(String file_path, @RequestParam(name = "on_line", defaultValue = "false") boolean on_line, HttpServletResponse response) throws Exception{


        uploadService.downLoad(file_path, response, on_line);

    }
}
